#include <iostream>
using namespace std;
int main()
{
    char a[11];
    char b[11];
    char c[11];
    int count;
    cin >> count;
    char *p1, *p2, *p3;
    int x1, y1, x2, y2, x3, y3;
    for (int i = 0; i < count; i++)
    {
        cin >> a >> b >> c;
        p1 = a;
        p2 = b;
        p3 = c;
        int n;
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
        n = x1;
        while (n - 1)
        {
            p1++;
            n--;
        }
        n = x2;
        while (n - 1)
        {
            p2++;
            n--;
        }
        n = x3;
        while (n - 1)
        {
            p3++;
            n--;
        }
        char *p = new char[y1 - x1 + y2 - x2 + y3 - x3 + 4];
        char *px = p;
        for (int i = x1; i <= y1; i++)
        {
            *p = *p1;
            p++;
            p1++;
            /* code */
        }
        for (int i = x2; i <= y2; i++)
        {
            *p = *p2;
            p++;
            p2++;
            /* code */
        }
        for (int i = x3; i <= y3; i++)
        {
            *p = *p3;
            p++;
            p3++;
            /* code */
        }
        *p = 'C';
        for (int i = 0; i < (y1 - x1 + y2 - x2 + y3 - x3 + 3); i++)
    {
            cout << *px;
            px++;
            /* code */
        }
        cout << endl;
        /* code */
    }

    return 0;
}
